package com.paranoid.flashcard.view;

import com.paranoid.flashcard.R;
import com.paranoid.flashcard.model.Deck;
import com.paranoid.flashcard.model.Deck.DownloadStatus;

import android.content.Context;
import android.database.Cursor;
import android.util.Log;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ProgressBar;
import android.widget.SimpleCursorAdapter;

public class DeckListAdapter extends SimpleCursorAdapter {
	Context mContext;
	Cursor mCursor;

	public DeckListAdapter(Context context, int layout, Cursor c,
			String[] from, int[] to) {
		super(context, layout, c, from, to);
		mContext = context;
		mCursor = c;
	}

	@Override
	public View getView(int position, View convertView, ViewGroup parent) {
		View view = super.getView(position, convertView, parent);
		mCursor.moveToPosition(position);
		long id = mCursor.getLong(0);
        DownloadStatus status = Deck.getDownloadStatus(mCursor);
		if (status == DownloadStatus.DOWNLOADING) {
			((ProgressBar)view.findViewById(R.id.progress_id)).setVisibility(View.VISIBLE);
		} else {
			((ProgressBar)view.findViewById(R.id.progress_id)).setVisibility(View.GONE);
		}
		Log.i("", "LOG: " + id + ", " + status);
		return view;
	}
	
	

}
